import Field from 'winged/utils/wt-model-field'
export default {
	title: '用戶',
	name: 'user',
	tableName: 'doctors',
	customFormComponent: 'wt-new-user',
	single: false,
	query: {
		method: 'GET',
		url: 'auth/users',
		transfer: false,
		pagination: true,
		// 在修改的时候需要进行单条记录查询，用于获取关联麻醉记录
		getOnEdit: false,
		countParam: 'totalNum'
	},
	// count: {
	// 	method: 'GET',
	// 	url: 'doctor/patient/surgery/count',
	// 	transfer: true,
	// 	extraParams: [
	// 		'user_id',
	// 	],
	// },
	new: {
		method: 'POST',
		url: 'auth/adduser',
		transfer: false,
		extraParams: [
		]
	},
	update: {
		method: 'POST',
		url: 'auth/adduser',
		transfer: false
	},
	delete: {
		method: 'DELETE',
		url: 'doctor/patient/surgery',
		transfer: true
	},
	id_field: {
		// 用于修改、删除操作的字段名
		name: 'user_id',
		// id字段查询结果中的tableName默认为'id'
		tableName: 'doctor_user_id'
	},
	fields: [
		{
			label: 'ID',
			type: Field.types.text,
			display: true,
			summary: true,
			noSave: true,
			tableName: 'doctor_user_id',

		}, {
			label: '用户名',
			type: Field.types.text,
			multiple: false,
			summary: true,
			noSave: true,
			display: true,
			formSize: 'small',
			minWidth:'120',
			name: 'phone',
			tableName: 'phone',
		},  {
			label: '用户名',
			type: Field.types.text,
			multiple: false,
			summary: true,
			display: false,
			formSize: 'small',
			name: 'username',
			tableName: 'username',
			extra:'推荐使用手机号码作为用户名'
		}, {
			label: '密码',
			type: Field.types.text,
			multiple: false,
			summary: true,
			noSave: true,
			display: false,
			formSize: 'small',
			name: 'password',
			tableName: 'password',
		}, {
			label: '姓名',
			type: Field.types.text,
			display: true,
			summary: true,
			name: 'name',
			tableName: 'name',
			minWidth:'120',
			formSize: 'small',
		}, {
			label: '所属科室',
			type: Field.types.text,
			display: true,
			noSave: true,
			summary: true,
			name: 'dpt_name',
			tableName: 'dpt_name',
			minWidth:'140',
			builder: function(data) {
				if (!data[this.tableName]){
					if (data.second_department_name==''){
						data[this.tableName] = data.department_name
					}else {
						data[this.tableName] = data.second_department_name
					}
				}
			},
		},  {
			label: '所属科室',
			type: Field.types.select,
			noFormDisplay: true,
			summary: true,
			display: false,
			name: 'department_id',
			tableName: 'department_id',
		}, {
			label: '所属科室',
			type: Field.types.select,
			display: false,
			summary: true,
			firstOptionsParam:'department_id',
			secondOptionsParam:'second_department_id',
			name: 'second_department_id',
			tableName: 'second_department_id',
			formSize: 'small',
			customComponent:'wt-department-select',
			paramsQuery: {
				method: 'DRONE',
				url: 'user_info/get_department_list',
				transfer: true,
				params:'departments',
				firstValue:'department_id',
				firstLable:'name'
			},
		}, {
			label: '角色',
			type: Field.types.text,
			summary: true,
			noSave: true,
			display: true,
			tableName: 'roles_display',
			minWidth:'260',
			builder: function(data) {
				let records = '' ;
				if (!data[this.tableName]||typeof data[this.tableName]=='object') {
					let items = data.doctor_roles;
					for (let i=0;i<items.length;i++){
						if (i == items.length-1){
							records+=items[i].name
						}else {
							records+=items[i].name+'，'
						}

					}
					data[this.tableName] = records;
				}
			},
		}, {
			label: '角色',
			type: Field.types.select,
			display: false,
			name: 'roles',
			tableName: 'roles',
			customComponent: 'wt-model-field-select',
			optionsParam:'roles',
			builder: function(data) {
				var role = data.doctor_roles;
				// var arr = [];
				// for (var i=0;i<role.length;i++){
				// 	arr.push(role[i].id)
				// }
				data.roles = data.doctor_roles;
			},
		},{
			label: '职称',
			type: Field.types.select,
			// display: true,
			// noFormDisplay: true,
			display: false,
			summary: true,
			name: 'tech_title',
			tableName: 'tech_title',
			options: [
				{
					label: '无',
					value: '0'
				}, {
					label: '助理医师',
					value: '1'
				}, {
					label: '医师',
					value: '2'
				}, {
					label: '主治医师',
					value: '3'
				}, {
					label: '副主任医师',
					value: '4'
				}, {
					label: '主任医师',
					value: '5'
				},
			],
			builder:function (data) {
				let grade;
				if (!data[this.tableName]){
					switch (data.tech_title){
						case '0':
							grade = '无';
							break;
						case '1':
							grade = '助理医师';
							break;
						case '2':
							grade = '医师';
							break;
						case '3':
							grade = '主治医师';
							break;
						case '4':
							grade = '副主任医师';
							break;
						case '5':
							grade = '主任医师';
							break;
						default:
							grade = '';
							break;
					}
					data[this.tableName] = grade;
				}
			},
			rules: [{ required: false, message: '请选择职称', trigger: 'change' }]
},
	]
}